﻿// ***********************************************************************
// Assembly         : OSS.ModelViewer
// Author           : tian_
// Created          : 09-05-2018
//
// Last Modified By : tian_
// Last Modified On : 09-05-2018
// ***********************************************************************
// <copyright file="ZfTreeListManager.cs" company="">
//     Copyright ©  2017
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.Windows.Forms;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using ZFGK.DevExprss.Controls;
using ZFGK.OSG.UI;

namespace OSS.ModelViewer.Utility
{
    /// <summary>
    /// Class ZfTreeListManager.
    /// </summary>
    public static class ZfTreeListManager
    {
        /// <summary>
        /// Gets or sets the osg earth view.
        /// </summary>
        /// <value>The osg earth view.</value>
        private static ZfOsgViewCtrl ZfOsgViewCtrl
        {
            get
            {
                return null;//ModelApp.OsgFormInstance.OsgViewCtrl;
            }
        }

        /// <summary>
        /// The tree list
        /// </summary>
        private static ZfTreeList _treeList = new ZfTreeList();

        /// <summary>
        /// Gets the tree list.
        /// </summary>
        /// <value>The tree list.</value>
        public static ZfTreeList TreeList
        {
            get { return _treeList; }
        }

        /// <summary>
        /// Initializes the TreeView model.
        /// </summary>
        public static void InitTreeViewModel()
        {
            TreeList.BeginUpdate();
            TreeList.Nodes.Clear();
            var rootNode = TreeList.AppendNode(new object[] { "模型" }, null, null);
            TreeList.EndUpdate();
        }

        /// <summary>
        /// TreeViews the model on after check.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="TreeViewEventArgs" /> instance containing the event data.</param>
        public static void TreeListOnAfterCheckNode(object sender, NodeEventArgs args)
        {
//             var argsNode = args.Node;
// 
//             // 先去掉回调，方式循环调用
//             argsNode.TreeList.AfterCheckNode -= TreeListOnAfterCheckNode;
// 
//             TreeList.BeginUpdate();
//             string strMsg = null;
//             try
//             {
//                 LoadOrDeleteModelView(argsNode);
//             }
//             catch (Exception e)
//             {
//                 MsgManager.Cation = "更新树错误！";
//                 MsgManager.AppendLine(e.GetAllExMessage());
//                 MsgManager.Show();
//             }
//             TreeList.EndUpdate();
// 
//             // 加载回调
//             argsNode.TreeList.AfterCheckNode += TreeListOnAfterCheckNode;
        }

        /// <summary>
        /// Loads the or delete model view.
        /// </summary>
        /// <param name="treeNode">The tree node.</param>
        public static void LoadOrDeleteModelView(TreeListNode treeNode)
        {
//             if (treeNode.Tag is UserProject || treeNode.Tag is UserGroup)
//             {
//                 foreach (TreeListNode treeNodeChild in treeNode.Nodes)
//                 {
//                     treeNodeChild.Checked = treeNode.Checked;
//                     LoadOrDeleteModelView(treeNodeChild);
//                 }
//             }
//             else if (treeNode.Tag is UserModel)
//             {
//                 var userModel = treeNode.Tag as UserModel;
//                 if (treeNode.Checked)
//                 {
//                     userModel.AddOrReplaceModel(OsgViewCtrl.MapNode.getMapSRS());
//                 }
//                 else
//                 {
//                     userModel.DeleteModel();
//                 }
//             }
//             foreach (TreeListNode treeNodeChild in treeNode.Nodes)
//             {
//                 treeNodeChild.Checked = treeNode.Checked;
//                 LoadOrDeleteModelView(treeNodeChild);
//             }
        }


    }
}
